package com.zrf.base.knowledge.leetcode.primary;

/**
 * 股票最大收益
 */
public class ShareMaxIncome {

    public static void main(String[] args) {
        int[] a = new int[]{7,6,4,3,1};
        System.out.println(maxIncome(a));
    }

    public static int maxIncome(int[] prices) {
        if (prices.length < 2){
            return 0;
        }
        int result = 0;
        for (int i = 1; i < prices.length; i++) {
            int diff = prices[i] - prices[i-1];
            if (diff > 0) {
                result += diff;
            }
        }
        return result;
    }
}
